package com.chinafocus.gc;

import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

/**
 * @author wd
 * @version 1.0
 * @date 2020/6/19
 * @Described：常量池内存溢出探究
 *-Xmx5m  -XX:+PrintGCDetails -XX:+PrintGCDateStamps
 * 运行时常量池存放在堆中
 *
 */
@Slf4j
public class ConstantOutOfMemory {
    public static void main(String[] args) throws Exception {
        try {
            List strings = new ArrayList();
            int i = 0;
            while (true) {
                log.info(i+"");
                strings.add(String.valueOf(i++).intern());
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }
}

